/*
 * Copyright (c) 2008, Hugh Sanderson, http://gamehaxe.com/
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 *
 */
 
/*
 This code tries to match the flash algorithm for sub-pixel placement.
 Is seems that coordinates are placed on the cornders of pixels, and
 the pixels are sampled on their centres.
 However, there is some special case code for horizontal and vertical
 lines.

*/


import flash.display.Graphics;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;

import flash.display.CapsStyle;
import flash.display.GradientType;
import flash.display.JointStyle;
import flash.display.SpreadMethod;
import flash.display.LineScaleMode;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.events.Event;


class GraphicsTest extends Sprite
{
   static function main()
   {
      neash.Lib.Init("GraphicsTest",640,480,false,true); 
      neash.Lib.SetBackgroundColour(0xffffff); 

      new GraphicsTest();

      //neash.Lib.SetFrameRate(1000);
      //neash.Lib.mShowFPS = true;
      neash.Lib.Run(); 
   }


   public function new()
   {
      super();
      flash.Lib.current.addChild(this);

      var gfx = graphics;

      gfx.lineStyle( 1, 0xffa0a0 );
      for(x in 0...25)
      {
         gfx.moveTo(x*20,0);
         gfx.lineTo(x*20,480);
      }
      for(y in 0...33)
      {
         gfx.moveTo(0,y*20);
         gfx.lineTo(640,y*20);
      }


      for(x in 0...11)
      {
         var pos = 20 + x*20.1;
         for(y in 0...10)
         {
            gfx.lineStyle( 1.0 + y*0.1, 0x000000 );
            gfx.moveTo(pos, 20 + y*20 );
            gfx.lineTo(pos+5, 30 + y*20 );
         }

     }

      gfx.lineStyle();
      for(x in 0...11)
      {
         var pos = 20 + x*20.1;
         for(y in 0...10)
         {
            gfx.beginFill(0x0000ff);
            gfx.drawRect(pos+322,y*20+42, 10,10);
            gfx.endFill();
         }

     }


     gfx.lineStyle( 2, 0x000000 );
     gfx.moveTo(300, 20);
     gfx.lineTo(320, 20);

     gfx.moveTo(323, 20);
     gfx.lineTo(340, 20.2);

     var matrix = new Matrix();
     matrix.tx = 0.5;
     matrix.ty = 0.5;
     var bmp = new BitmapData(8,8,false,I32.ZERO);
     bmp.setPixel(6,6,0xffffff);
     gfx.lineStyle();
     gfx.beginBitmapFill(bmp,matrix,true,true);
     gfx.moveTo(300, 60);
     gfx.lineTo(320, 60);
     gfx.lineTo(320, 80);
     gfx.lineTo(300, 80);
     gfx.lineTo(300, 60);

   }

}
